package com.ctbu.tools;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseResult<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;

    public  static <T>ResponseResult<T> success(T data){
        ResponseResult<T> result = new ResponseResult<>();
        result.setData(data);
        result.setCode(StatusEnum.SUCCESS.code);
        return result;
    }
    public static <T>ResponseResult<T> success(T data,String message){
        ResponseResult<T> result = new ResponseResult<>();
        result.setData(data);
        result.setCode(StatusEnum.SUCCESS.code);
        result.setMessage(message);
        return result;
    }
    public static <T>ResponseResult<T> fail(StatusEnum statusEnum){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(statusEnum.code);
        result.setMessage(statusEnum.message);
        return result;
    }
    public static <T>ResponseResult<T> fail(StatusEnum statusEnum,String errorMsg){
        ResponseResult<T> result = new ResponseResult<>();
        result.setCode(statusEnum.code);
        result.setMessage(errorMsg);
        return result;
    }

}
